<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>登录页面 - ${config.web_site_title}</title>
<#assign path="${request.getContextPath()}">
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="${config.web_site_keywords}">
<meta name="description" content="${config.web_site_description}">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<link href="css/style.min.css" rel="stylesheet">
<style>
.login-form .has-feedback {
    position: relative;
}
.login-form .has-feedback .form-control {
    padding-left: 36px;
}
.login-form .has-feedback .mdi {
    position: absolute;
    top: 0;
    left: 0;
    right: auto;
    width: 36px;
    height: 36px;
    line-height: 36px;
    z-index: 4;
    color: #dcdcdc;
    display: block;
    text-align: center;
    pointer-events: none;
}
.login-form .has-feedback.row .mdi {
    left: 15px;
}
</style>
</head>
  
<body class="center-vh" style="background-image: url(images/login-bg-2.jpg); background-size: cover;">
<div class="card card-shadowed p-5 w-420 mb-0 mr-2 ml-2" id="login-box">
  <div class="text-center mb-3">
    <a href="index"> <h2>wanAdmin</h2> </a>
  </div>

  <form id="submitForm" action="" method="post" class="login-form" onsubmit="return doLogin();">
    <div class="form-group has-feedback">
      <span class="mdi mdi-account" aria-hidden="true"></span>
      <input type="text" class="form-control" id="username" name="username" placeholder="用户名" value="admin">
    </div>

    <div class="form-group has-feedback">
      <span class="mdi mdi-lock" aria-hidden="true"></span>
      <input type="password" class="form-control" id="password" name="password" placeholder="密码" value="123456">
    </div>
    
    <div class="form-group has-feedback row">
      <div class="col-7">
        <span class="mdi mdi-check-all form-control-feedback" aria-hidden="true"></span>
        <input type="text" name="captcha" class="form-control" placeholder="验证码">
      </div>
      <div class="col-5 text-right">
        <img src="images/captcha.png" class="pull-right" id="captcha" style="cursor: pointer;" onclick="this.src=this.src+'?d='+Math.random();" title="点击刷新" alt="captcha">
      </div>
    </div>

    <div class="form-group">
      <button class="btn btn-block btn-primary" type="submit">立即登录</button>
    </div>
  </form>
  
  <p class="text-center text-muted mb-0">${config.web_site_copyright}</p>
</div>
  
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap-notify.min.js"></script>
<!--layer弹窗插件 -->
<script type="text/javascript" src="js/layer/layer.min.js"></script>
<!--表单验证 -->
<script type="text/javascript" src="js/jquery-validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/jquery-validate/messages_zh.min.js"></script>
<script type="text/javascript" src="wanAdmin/common.js"></script>
<script type="text/javascript">
if(window != top) {				    
    top.location.href = window.location.href;
}

if (getQueryVariable('timeout') == '1') {
	layer.alert('登录超时，请重新登录');
}
if (getQueryVariable('expired') == '1') {
	layer.alert('账号在其他地方登录');
}

validateForm({
	'username': {
		required: true
	},
	'password': {
		required: true
	},
	'captcha': {
		required: true
	}
});

function doLogin() {
	if (!$('#submitForm').valid()) {
		return;
	}
	
	ajaxPost({
		url: 'doLogin',
        data: $('#submitForm').serialize(),
        success: function(r) {
            if (r.code == 0) {
                location.href = '${path}/';
            } else {
            	$('#captcha').click();
            	$('input[name="captcha"]').val("");
            	notifyWarning(r.message);
            }
        }
	});
	
	return false;
}
</script>
</body>
</html>